<template>
  <div class="news-list">
    <my-header titleName="新闻资讯"></my-header>
    <ul>
      <li v-for="item in newsList" :key="item.id" @click="JumpTo(item.id)">
        <div class="news-item">
          <img :src="item.img_url" :alt="item.title">
          <div class="content">
            <p class="content-title">{{item.title}}</p>
            <p class="content-info">
              <span class="content-time">{{item.add_time|filterTime}}</span>
              <span class="content-click">{{item.click}}</span>
            </p>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import { getNews } from '@/api'
import myHeader from '@/components/myHeader'
export default {
  components: {
    myHeader
  },
  data () {
    return {
      newsList: []
    }
  },
  created () {
    this.initNews()
  },
  methods: {
    initNews () {
      getNews().then(res => {
        this.newsList = res.message
        console.log(res)
      })
    },
    JumpTo (id) {
      this.$router.push({ name: 'newslistdetail', params: { id: id } })
    }
  }

}
</script>
<style lang="less" scoped>
.news-list {
  ul {
    margin: 45px 0 0 0;
    li {
      padding: 5px;
    }
  }
  .news-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      width: 100px;
      height: 50px;
      margin-right: 10px;
      flex: 1;
    }
    .content {
      flex: 2;
      width: 250px;
      .content-title {
        font-size: 14px;
        font-weight: bold;
      }
      .content-info {
        display: flex;
        justify-content: space-between;
        color: #26a2ff;
        font-size: 12px;
      }
    }
  }
}
</style>
